package com.yuqiao.read.design.command;

public class RemoteController {
    Command[] onCommonands,offCommands;
    public RemoteController(){
        onCommonands = new Command[7];
        offCommands = new Command[7];
        Command noCommand = new NoCommand();
        for(int i=0;i<7;i++){
            onCommonands[i] = noCommand;
            offCommands[i] = noCommand;
        }
    }
    public void setCommond(int slot,Command onCommand,Command offCommand){
        onCommonands[slot] = onCommand;
        offCommands[slot] = offCommand;
    }

    public void onButtonWasPressed(int solt){
        onCommonands[solt].execute();
    }

    public void offButtonWasPressed(int solt){
        offCommands[solt].execute();
    }

    public String toString(){
        StringBuilder sb = new StringBuilder();
        sb.append("\n--------Remote-Control-------\n");
        for(int i=0;i<onCommonands.length;i++){
            sb.append("[slot"+i+"]"+onCommonands[i].getClass().getName()
            +" "+offCommands[i].getClass().getName()+"\n");
        }
        return sb.toString();
    }
}
